package com.dy.springcloud.controller;

import com.dy.springcloud.entity.Member;
import com.dy.springcloud.entity.Result;
import com.dy.springcloud.service.MemberService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class MemberController {
    @Resource
    private MemberService memberService;

    @GetMapping("/member/get/{id}")
    public Result getMemberById(@PathVariable("id") Long id) {
        Member member = memberService.getMemberById(id);
        if (member != null) {
            return Result.success("查询用户成功 10000",member);
        }
        return Result.error("402","用户不存在");
    }

    @PostMapping("/member/save")
    public Result saveMember(@RequestBody Member member) {
        int affected = memberService.save(member);
        if (affected > 0) {
            return Result.success("添加用户成功",null);
        }
        return Result.error("401","添加用户失败");
    }
}
